package com.example.java.collection;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;

public class CollectionApp {
    /**
     * 映射 Map
     */
    private static void mapTestOfMap(){
        Map<String, Integer> map = new HashMap<>();
        map = new LinkedHashMap<>();
        map.merge("1", 1, Integer::sum);
    }

    private static void mapTestOfNavigableMap(){
        NavigableMap<String ,String> navigableMap = new TreeMap<>();
    }

    /**
     * 队列 Queue
     */
    private static void queueTestOfQueue(){
        Queue<String> queue = new LinkedList<>(); //链表实现了队列.
        queue.offer("曾"); //入队
        queue.offer("梦");
        queue.offer("甜");
        while (!queue.isEmpty()){
            System.out.println(queue.poll());//出队
        }
//        Collections.binarySearch();
        Properties properties = new Properties();
//        properties.
    }

    /**
     * 双端队列 Deque 继承于Queue 队列用途
     */
    private static void queueTestOfDeque(){
        Deque<String> deque = new ArrayDeque<>();
        deque = new ArrayDeque<>();
        deque.offer("你");//入队
        deque.offer("好");
        deque.poll();//出队
    }

    /**
     * 栈用途
     */
    private static void stackTestOfDeque(){
        Deque<String> stack = new LinkedList<>();
        stack = new ArrayDeque<>();
        stack.push("你");//入栈
        stack.push("好");
        stack.peek();//查看栈顶元素
        stack.pop();//出栈 null时抛出异常
        stack.poll();//出栈
    }

    /**
     * 集合 Set
     */
    private static void setTestOfSet(){
        Set<String> set = new HashSet<>(); //哈希表
        set = new LinkedHashSet<>(); //链表哈希
        set= new TreeSet<>();
    }

    /**
     * 表 List
     */
    private static void listTestOfList(){
        List<String> list = new ArrayList<>(); //数组表
        list = new LinkedList<>();//链表
        list.listIterator();

    }

    /**
     * 栈 这个栈是线程安全的 效率地下 弃用
     */
    @Deprecated
    private static void stackTest(){
        Stack<String> stack = new Stack<>();
        stack.push("曾");
        stack.push("天");
        stack.push("大");
        while (!stack.isEmpty()){
            System.out.println(stack.pop());
        }
    }

    private static void collectionAndMap(){
        Collection<Object> collection; //广义集合
            List<Object> list; //表
                AbstractList<Object> abstractList; //抽象表
                    AbstractSequentialList<Object> abstractSequentialList; //抽象顺序表
                        LinkedList<Object> linkedList; //链表 //非线程安全 可用ConcurrentLinkedDeque代替;
                    ArrayList<Object> arrayList;//数组表
                    Vector<Object> vector;//向量，线程安全
                        Stack<Object> stack;//栈
            Queue<Object> queue; //队列
                Deque<Object> deque; //双端队列
                    LinkedList<Object> linkedList1; //双端链队列
                    ArrayDeque<Object> arrayDeque; //双端数组队列
                    ConcurrentLinkedDeque<Object> concurrentLinkedDeque; //并发双端链队列
                AbstractQueue<Object> abstractQueue;//抽象队列
                    PriorityQueue<Object> priorityQueue;//优先队列， 优先级最高的
                    ConcurrentLinkedQueue<Object> concurrentLinkedQueue; //并发链队列

            Set<Object> set; //狭义上的集合
                SortedSet<Object> sortedSet;//排序集
                    NavigableSet<Object> navigableSet; //导航集
                        TreeSet<Object> treeSet; //树集

        Map<Object, Object> map; //map
            AbstractMap<Object, Object> abstractMap;//抽象map
                HashMap<Object, Object> hashMap;//哈希map
                TreeMap<Object, Object> treeMap;//树map
            SortedMap<Object, Object> sortedMap;//排序map
                NavigableMap<Object, Object> navigableMap; //导航map
                    TreeMap<Object, Object> treeMap1;//导航树map
            Hashtable<Object, Object> hashtable;//哈希表,//线程安全的 //其父类被废弃
            ConcurrentMap<Object, Object> concurrentMap;//并发map
                ConcurrentHashMap<Object, Object> concurrentHashMap; //并发hashmap
    }
}
